﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jamhee.Noctiluca.Common;
using System.IO;
using System.Threading;

namespace Jamhee.Noctiluca.LightWiki.PropertyFiles
{
    class WikiPageInfo
    {
        private IniFile _iniFile = null;

        #region

        private const string SECTION_PAGE = "PAGE";
        private const string SECTION_PAGE_KEY_TITLE = "title";

        #endregion

        public WikiPageInfo(string path)
        {
            _iniFile = new IniFile(path);
        }

        public string GetPageTitle()
        {
            if (_iniFile.Exist())
            {
                return _iniFile.IniReadValue(SECTION_PAGE, SECTION_PAGE_KEY_TITLE);
            }

            return "";
        }

        public void SetPageTitle(string title)
        {
            if (!_iniFile.Exist())
            {
                _iniFile.Create();

                // Wait to make sure the file is created
                Thread.Sleep(100);
            }

            _iniFile.IniWriteValue(SECTION_PAGE, SECTION_PAGE_KEY_TITLE, title);
        }
    }
}